﻿package mortal.game.view.blackMarket
{
    import Message.Public.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.ui.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;

    public class BlackMarketModule extends BaseWindow
    {
        protected var _goodsList:GTileList;
        private var _rechargeBtn:GLoadingButton;
        private var _doubleCountDown:SecTimerBitmapView;
        private var _consumeBox:GConsumeBox;
        protected var _pageSelecter:PageSelecter;

        public function BlackMarketModule()
        {
            setSize(813, 530);
            this.title = Language.getString(35109);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.blackMarketBg, 8, 35, this));
            this._rechargeBtn = UIFactory.gLoadingButton(ResFileConst.investmentRechargeBtn, 633, 162, 141, 43, this);
            this._rechargeBtn.configEventListener(MouseEvent.CLICK, this.rechargeHandler);
            this._consumeBox = UIFactory.gConsumeBox("", 607, 219, 0, this);
            this._consumeBox.addItem(ConsumeData.ShowMoneyType, EPriceUnit._EPriceUnitGold, 0, Language.getString(35110), "1");
            this._doubleCountDown = UIFactory.secTimerBitmapView(155, 221, "rechargeActivityTimeNumber.png", 11, 15, -2, this, 10);
            this._doubleCountDown.customCharIndex = {0:0, 1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, ::10};
            this._doubleCountDown.setParse("hh:mm:ss");
            this._doubleCountDown.timeOutHandler = this.timeOutCallBack;
            this._goodsList = UIFactory.tileList(35, 256, 800, 480, this);
            this._goodsList.columnWidth = 240;
            this._goodsList.rowHeight = 104;
            this._goodsList.horizontalGap = 8;
            this._goodsList.verticalGap = 5;
            this._goodsList.setStyle("cellRenderer", BlackMarketRender);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = AlignMode.CENTER;
            this._pageSelecter = UIFactory.pageSelecter(339, 485, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.ComboBg, _loc_1);
            this._pageSelecter.pageTextBoxSize = 50;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            this._pageSelecter.currentPage = 1;
            this.refreshInfo();
            this.updateLeftTime();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._goodsList.dispose(param1);
            this._goodsList = null;
            this._pageSelecter.dispose(param1);
            this._pageSelecter = null;
            this._rechargeBtn.dispose(param1);
            this._rechargeBtn = null;
            this._consumeBox.dispose(param1);
            this._consumeBox = null;
            this._doubleCountDown.dispose(param1);
            this._doubleCountDown = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function updateLeftTime() : void
        {
            var _loc_1:* = ClockManager.instance.nowDate;
            var _loc_2:Number = 6;
            var _loc_3:* = _loc_2 - _loc_1.hours % _loc_2;
            var _loc_4:* = new Date(_loc_1.fullYear, _loc_1.month, _loc_1.date, _loc_1.hours + _loc_3, 0, 0, 0);
            var _loc_5:* = _loc_4.time - _loc_1.time;
            this._doubleCountDown.setLeftTime(_loc_5 * 0.001);
            return;
        }// end function

        private function refreshInfo() : void
        {
            GameProxy.guild.getBlackMarketConfig();
            return;
        }// end function

        private function timeOutCallBack() : void
        {
            this.refreshInfo();
            this.updateLeftTime();
            return;
        }// end function

        private function rechargeHandler(event:MouseEvent) : void
        {
            GameUtil.gotoRecharge(ModuleTypeConst.BlackMarket);
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.updateItem();
            return;
        }// end function

        private function sortItem(param1:BlackMarketData, param2:BlackMarketData) : int
        {
            if (param1.remainInfo.itemCode > param2.remainInfo.itemCode)
            {
                return -1;
            }
            return 1;
        }// end function

        public function updateItem() : void
        {
            var _loc_4:Object = null;
            var _loc_5:int = 0;
            var _loc_6:BlackMarketData = null;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_1:* = new DataProvider();
            var _loc_2:* = Cache.instance.blackMarket.rebateInfoDic;
            var _loc_3:Array = [];
            for each (_loc_6 in _loc_2)
            {
                
                if (_loc_6.remainInfo)
                {
                    _loc_3.push(_loc_6);
                }
            }
            _loc_3.sort(this.sortItem);
            _loc_7 = (this._pageSelecter.currentPage - 1) * 6;
            _loc_8 = this._pageSelecter.currentPage * 6 > _loc_3.length ? (_loc_3.length) : (this._pageSelecter.currentPage * 6);
            var _loc_9:* = _loc_7;
            while (_loc_9 < _loc_8)
            {
                
                _loc_6 = _loc_3[_loc_9];
                _loc_4 = {info:_loc_6};
                _loc_1.addItem(_loc_4);
                _loc_9++;
            }
            this._goodsList.dataProvider = _loc_1;
            this._pageSelecter.maxPage = Math.ceil(_loc_3.length / 6);
            return;
        }// end function

    }
}
